<?php

function setReporting() {
if (DEVELOPMENT_ENVIRONMENT == true) {
	error_reporting(E_ALL);
	ini_set('display_errors','On');
} else {
	error_reporting(E_ALL);
	ini_set('display_errors','Off');
	ini_set('log_errors', 'On');
	ini_set('error_log', ROOT.'/tmp/logs/error.log');
}
}

//function stripSlashesDeep($value) {
//	$value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
//	return $value;
//}
//
//function removeMagicQuotes() {
//if ( get_magic_quotes_gpc() ) {
//	$_GET    = stripSlashesDeep($_GET   );
//	$_POST   = stripSlashesDeep($_POST  );
//	$_COOKIE = stripSlashesDeep($_COOKIE);
//}
//}

//function unregisterGlobals() {
//    if (ini_get('register_globals')) {
//        $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
//        foreach ($array as $value) {
//            foreach ($GLOBALS[$value] as $key => $var) {
//                if ($var === $GLOBALS[$key]) {
//                    unset($GLOBALS[$key]);
//                }
//            }
//        }
//    }
//}

function callHook() {
	global $ac;
	
	$urlArray = array();
	$urlArray = explode("/", $ac);

    $controller = $urlArray[0];
    array_shift($urlArray);
    $action = $urlArray[0];
    array_shift($urlArray);
    $queryString = $urlArray;
	
    $controllerName = $controller;
    $controller = ucwords($controller);
    $model = rtrim($controller, 's');
	
	require_once(ROOT . '/application/controllers/'. $controller . '.php');
	//var_dump($model);
    $controller .= 'Controller';
			
	require_once(ROOT . '/application/models/'. $model . '.php');
	
    $dispatch = new $controller($model, $controllerName, $action);
	
    if ((int)method_exists($controller, $action)) {
        call_user_func_array(array($dispatch,$action), $queryString);
    } else {
        
    }
}

setReporting();
//removeMagicQuotes();
//unregisterGlobals();
callHook();
